********************************************************************************
* Turnout
********************************************************************************

use dataset_voters, clear

gen post = 1 if year == 2012
replace post = 0 if year == 2000
gen anyfrackingXpost = anyfracking*post
tabulate year, gen(year_)
egen state_year = group(di_state year)

eststo clear

eststo: reg turnout lnwells i.state_year, a(zipcode) cl(zipcode)
estadd local ZFE = "Yes"
estadd local YFE = "Yes"
eststo: reg turnout anywells i.state_year, a(zipcode) cl(zipcode)
estadd local ZFE = "Yes"
estadd local YFE = "Yes"
eststo: reg turnout anyfrackingXpost i.state_year, a(zipcode) cl(zipcode)
estadd local ZFE = "Yes"
estadd local YFE = "Yes"

keep if highfracking == 1
eststo: reg turnout lnwells i.state_year, a(zipcode) cl(zipcode)
estadd local ZFE = "Yes"
estadd local YFE = "Yes"
eststo: reg turnout anywells i.state_year, a(zipcode) cl(zipcode)
estadd local ZFE = "Yes"
estadd local YFE = "Yes"
eststo: reg turnout anyfrackingXpost i.state_year, a(zipcode) cl(zipcode)
estadd local ZFE = "Yes"
estadd local YFE = "Yes"

label variable lnwells "Log wells"
label variable anywells "Any wells"
label variable anyfrackingXpost "Ever fracked X post"

#delimit;

esttab 
	using "_output/tableA7a.tex"
	,
		replace
		booktabs
		order(lnwells anywells anyfrackingXpost)
		drop(*year* _cons)
		cells(b(fmt(3) star) se(par))
		compress
		label
		gap
		collabels(none)
		nomtitles
		width(\linewidth)
		mgroups(
			"All states" "High fracking states", 
			pattern(1 0 0 1 0 0)
			prefix(\multicolumn{@span}{c}{) suffix(})
			span erepeat(\cmidrule(lr){@span})
		)	
		stats(
			YFE
			ZFE
			N_clust
			N
			,
				label(
					"State-year fixed effects"
					"Zip code fixed effects" 
					"Clusters"
					"Observations"
				)
				fmt(0 %20.0fc)
		)
		;
	
#delimit cr

********************************************************************************
* Contributions
********************************************************************************

use dataset_donors, clear

gen post = 1 if year == 2012
replace post = 0 if year == 2000
gen anyfrackingXpost = anyfracking*post

tabulate year, gen(year_)
egen state_year = group(STATE year)

eststo clear
eststo: areg ltotamount lnwells i.state_year, a(zipcode) cl(zipcode)
estadd local ZFE = "Yes"
estadd local YFE = "Yes"
eststo: areg ltotamount anywells i.state_year, a(zipcode) cl(zipcode)
estadd local ZFE = "Yes"
estadd local YFE = "Yes"
eststo: areg ltotamount anyfrackingXpost i.state_year, a(zipcode) cl(zipcode)
estadd local ZFE = "Yes"
estadd local YFE = "Yes"

keep if highfracking == 1
eststo: areg ltotamount lnwells i.state_year, a(zipcode) cl(zipcode)
estadd local ZFE = "Yes"
estadd local YFE = "Yes"
eststo: areg ltotamount anywells i.state_year, a(zipcode) cl(zipcode)
estadd local ZFE = "Yes"
estadd local YFE = "Yes"
eststo: areg ltotamount anyfrackingXpost i.state_year, a(zipcode) cl(zipcode)
estadd local ZFE = "Yes"
estadd local YFE = "Yes"

label variable lnwells "Log wells"
label variable anywells "Any wells"
label variable anyfrackingXpost "Ever fracked X post"

#delimit;

esttab 
	using "_output/tableA7b.tex"
	,
		replace
		booktabs
		order(lnwells anywells anyfrackingXpost)
		cells(b(fmt(3) star) se(par))
		drop(*year* _cons*)
		compress
		label
		gap
		width(\linewidth)
		collabels(none)
		nomtitles
		mgroups(
			"All states" "High fracking states", 
				pattern(1 0 0 1 0 0)
				prefix(\multicolumn{@span}{c}{) suffix(})
				span erepeat(\cmidrule(lr){@span})
		)
		stats(
			YFE
			ZFE
			N_clust
			N,
				label(
					"State-year fixed effects"
					"Zip code fixed effects"
					"Clusters"
					"Observations"
				)
				fmt(0 %20.0fc)
		)	
		star(* 0.05 ** 0.01 *** 0.001)
		;
		
#delimit cr

********************************************************************************
* End
********************************************************************************
